<template>
    <div>
        <meta title="站点模块管理"></meta>

        <ManageTable border stripe :rowKey="tableData.rowKey" :columns="tableData.columns" :data="tableData.data" :btnGroup="tableData.btnGroup" :page="tableData.page">
        </ManageTable>

    </div>
</template>

<script>
    import AppFrame from "../../../libs/app-frame";
    import ManageTable from "../../../components/manage-table";
    export default {
        name: "name",
        data: function () {
            return {
                CurUserInfo: {},
                tableData: {
                    rowKey: "sm_id",
                    columns: [
                        {
                            title: "模块名称",
                            key: "sm_name",
                            width: 250,
                            ellipsis: true
                        },
                        {
                            title: "所用视图地址",
                            width: 150,
                            key: "sm_viewPath"
                        },
                        {
                            title: "访问地址",
                            key: "sm_url"
                        },
                        {
                            title: "备注信息",
                            width: 250,
                            key: "sm_remark"
                        },
                        {
                            title: "操作",
                            key: "action",
                            width: 180,
                            align: "center",
                            able: '禁止编辑',
                            render: (h, params) => {
                                let edit=h(
                                    "Button", {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.$router.push(
                                                    "/manage/CMS/site-module/edit?id=" + params.row.sm_id
                                                );
                                            }
                                        }
                                    },
                                    "设置"
                                );
                                let delDisabled=false;
                                if(params.row.sm_isSys){
                                    delDisabled=true;
                                }
                                let del=h(
                                    "Button", {
                                        props: {
                                            type: "error",
                                            size: "small",
                                            disabled:delDisabled,
                                        },
                                        style:"margin-left:10px",

                                        on: {
                                            click: async () => {
                                                let self=this;
                                                this.$Modal.confirm({
                                                    title:'删除提示',
                                                    content:'确定要删除吗？',
                                                    onOk:async function () {
                                                        let ret = await AppFrame.Http.Post("/manage-api/cms/site-module/del", {id:params.row.sm_id});
                                                        if(ret.Result){
                                                            self.find();
                                                        }
                                                    }
                                                    
                                                })
                                            }
                                        }
                                    },
                                    "删除"
                                );

                                return h("div", [
                                    edit,
                                    del
                                ]);
                            }
                        }
                    ],
                    data: [],
                    btnGroup: [],
                    page: {
                        total: 0,
                        current: 1,
                        pageSize: 20
                    }
                },
                QueryModel: {

                }
            };
        },
        components: {
            ManageTable
        },
        created: function () {
            this.CurUserInfo = AppFrame.UserInfo.getUserInfo();

            this.setDefaultData();
            this.find();
        },
        watch: {
            $route: function () {
                //当路由改变时
                this.setDefaultData();
                this.find();
            }
        },
        methods: {
            setDefaultData: function () {

            },

            find: function () {
                try {
                    let self = this;
                    let PostData = {};

                    self.tableData.data.splice(0, self.tableData.data.length);
                    AppFrame.Http.Post("/manage-api/cms/site-module/getItems", PostData).then(function (Ret) {
                        self.tableData.page.total = 0;
                        Ret.Data.forEach(function (item) {
                            self.tableData.data.push(item);
                        });
                    }).catch(function (err) {
                            self.$Message.error(JSON.stringify(err));
                        });
                } catch (err) {
                    console.log(err);
                }
            }
        }
    };
</script>

<style scoped>

</style>
